package com.jack.base.desiginmodel.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhang_j on 2019/12/23
 */
public class Subject {

    private List<Observer> observerList = new ArrayList<>();

    private int state;

    public void setState(int state){
        this.state = state;
        this.notifyAllObserve();
    }

    public int getState(){
        return this.state;
    }

    public void attach(Observer observer){
        observerList.add(observer);
    }

    private void notifyAllObserve(){
        observerList.forEach(o->{
            o.update();
        });
    }
}
